.class public Lcom/nemustech/tiffany/util/TFImageLoader;
.super Ljava/lang/Thread;
.source "TFImageLoader.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/nemustech/tiffany/util/TFImageLoader$OnItemUpdateListener;,
        Lcom/nemustech/tiffany/util/TFImageLoader$Cell;
    }
.end annotation


# static fields
.field private static final TAG:Ljava/lang/String; = "TFImageLoader"


# instance fields
.field private mIdle:Z

.field private mIndexArray:Ljava/util/LinkedList;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/LinkedList",
            "<",
            "Ljava/lang/Integer;",
            ">;"
        }
    .end annotation
.end field

.field private mItemUpdateListener:Lcom/nemustech/tiffany/util/TFImageLoader$OnItemUpdateListener;

.field private mPaused:Z

.field private mSlotArray:Ljava/util/HashMap;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/HashMap",
            "<",
            "Ljava/lang/Integer;",
            "Lcom/nemustech/tiffany/util/TFImageLoader$Cell;",
            ">;"
        }
    .end annotation
.end field

.field private mThreadLive:Z


# direct methods
.method public constructor <init>()V
    .locals 1

    .prologue
    .line 29
    invoke-direct {p0}, Ljava/lang/Thread;-><init>()V

    .line 30
    new-instance v0, Ljava/util/LinkedList;

    invoke-direct {v0}, Ljava/util/LinkedList;-><init>()V

    iput-object v0, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mIndexArray:Ljava/util/LinkedList;

    .line 31
    new-instance v0, Ljava/util/HashMap;

    invoke-direct {v0}, Ljava/util/HashMap;-><init>()V

    iput-object v0, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mSlotArray:Ljava/util/HashMap;

    .line 32
    return-void
.end method


# virtual methods
.method public addQueue(Lcom/nemustech/tiffany/util/TFImageLoader$Cell;)V
    .locals 5
    .parameter "cell"

    .prologue
    .line 57
    monitor-enter p0

    .line 62
    :try_start_0
    iget v3, p1, Lcom/nemustech/tiffany/util/TFImageLoader$Cell;->mKey:I

    invoke-static {v3}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v1

    .line 69
    .local v1, key:Ljava/lang/Integer;
    :cond_0
    const/4 v0, 0x0

    .line 70
    .local v0, bRemoved:Z
    iget-object v3, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mSlotArray:Ljava/util/HashMap;

    invoke-virtual {v3, v1}, Ljava/util/HashMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Lcom/nemustech/tiffany/util/TFImageLoader$Cell;

    .line 72
    .local v2, prevSlot:Lcom/nemustech/tiffany/util/TFImageLoader$Cell;
    if-nez v2, :cond_3

    .line 88
    :goto_0
    iget-object v3, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mSlotArray:Ljava/util/HashMap;

    invoke-virtual {v3, v1, p1}, Ljava/util/HashMap;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 90
    iget-boolean v3, p1, Lcom/nemustech/tiffany/util/TFImageLoader$Cell;->mIsUrgent:Z

    if-eqz v3, :cond_5

    .line 92
    iget-object v3, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mIndexArray:Ljava/util/LinkedList;

    invoke-virtual {v3, v1}, Ljava/util/LinkedList;->addFirst(Ljava/lang/Object;)V

    .line 99
    :goto_1
    iget-boolean v3, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mIdle:Z

    if-eqz v3, :cond_1

    .line 101
    const/4 v3, 0x0

    iput-boolean v3, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mIdle:Z

    .line 102
    invoke-virtual {p0}, Ljava/lang/Object;->notify()V

    .line 106
    :cond_1
    iget-object v3, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mSlotArray:Ljava/util/HashMap;

    invoke-virtual {v3}, Ljava/util/HashMap;->size()I

    move-result v3

    iget-object v4, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mIndexArray:Ljava/util/LinkedList;

    invoke-virtual {v4}, Ljava/util/LinkedList;->size()I

    move-result v4

    if-eq v3, v4, :cond_2

    .line 107
    const-string v3, "TFImageLoader"

    const-string v4, "Array mismatch !!!!!"

    invoke-static {v3, v4}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    .line 108
    :cond_2
    monitor-exit p0

    .line 109
    :goto_2
    return-void

    .line 74
    :cond_3
    iget-object v3, v2, Lcom/nemustech/tiffany/util/TFImageLoader$Cell;->mModel:Lcom/nemustech/tiffany/world/TFModel;

    iget-object v4, p1, Lcom/nemustech/tiffany/util/TFImageLoader$Cell;->mModel:Lcom/nemustech/tiffany/world/TFModel;

    if-ne v3, v4, :cond_4

    .line 77
    monitor-exit p0

    goto :goto_2

    .line 108
    .end local v0           #bRemoved:Z
    .end local v1           #key:Ljava/lang/Integer;
    .end local v2           #prevSlot:Lcom/nemustech/tiffany/util/TFImageLoader$Cell;
    :catchall_0
    move-exception v3

    monitor-exit p0
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    throw v3

    .line 81
    .restart local v0       #bRemoved:Z
    .restart local v1       #key:Ljava/lang/Integer;
    .restart local v2       #prevSlot:Lcom/nemustech/tiffany/util/TFImageLoader$Cell;
    :cond_4
    :try_start_1
    iget-object v3, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mSlotArray:Ljava/util/HashMap;

    invoke-virtual {v3, v1}, Ljava/util/HashMap;->remove(Ljava/lang/Object;)Ljava/lang/Object;

    .line 82
    iget-object v3, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mIndexArray:Ljava/util/LinkedList;

    invoke-virtual {v3, v1}, Ljava/util/LinkedList;->remove(Ljava/lang/Object;)Z

    .line 83
    const/4 v0, 0x1

    .line 86
    if-nez v0, :cond_0

    goto :goto_0

    .line 96
    :cond_5
    iget-object v3, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mIndexArray:Ljava/util/LinkedList;

    invoke-virtual {v3, v1}, Ljava/util/LinkedList;->add(Ljava/lang/Object;)Z
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    goto :goto_1
.end method

.method public clearQueue()V
    .locals 2

    .prologue
    .line 35
    monitor-enter p0

    .line 36
    :try_start_0
    iget-object v0, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mSlotArray:Ljava/util/HashMap;

    invoke-virtual {v0}, Ljava/util/HashMap;->clear()V

    .line 37
    iget-object v0, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mIndexArray:Ljava/util/LinkedList;

    invoke-virtual {v0}, Ljava/util/LinkedList;->clear()V

    .line 38
    const-string v0, "TFImageLoader"

    const-string v1, "Image loader queue cleared"

    invoke-static {v0, v1}, Landroid/util/Log;->i(Ljava/lang/String;Ljava/lang/String;)I

    .line 39
    monitor-exit p0

    .line 40
    return-void

    .line 39
    :catchall_0
    move-exception v0

    monitor-exit p0
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    throw v0
.end method

.method public onPause()V
    .locals 1

    .prologue
    .line 157
    monitor-enter p0

    .line 158
    const/4 v0, 0x1

    :try_start_0
    iput-boolean v0, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mPaused:Z

    .line 159
    monitor-exit p0

    .line 160
    return-void

    .line 159
    :catchall_0
    move-exception v0

    monitor-exit p0
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    throw v0
.end method

.method public onResume()V
    .locals 1

    .prologue
    .line 163
    monitor-enter p0

    .line 164
    const/4 v0, 0x0

    :try_start_0
    iput-boolean v0, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mPaused:Z

    .line 165
    invoke-virtual {p0}, Ljava/lang/Object;->notify()V

    .line 166
    monitor-exit p0

    .line 167
    return-void

    .line 166
    :catchall_0
    move-exception v0

    monitor-exit p0
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    throw v0
.end method

.method public quit()V
    .locals 2

    .prologue
    .line 170
    monitor-enter p0

    .line 171
    const/4 v1, 0x0

    :try_start_0
    iput-boolean v1, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mThreadLive:Z

    .line 172
    invoke-virtual {p0}, Ljava/lang/Object;->notify()V

    .line 173
    monitor-exit p0
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 176
    :try_start_1
    invoke-virtual {p0}, Lcom/nemustech/tiffany/util/TFImageLoader;->join()V
    :try_end_1
    .catch Ljava/lang/InterruptedException; {:try_start_1 .. :try_end_1} :catch_0

    .line 180
    :goto_0
    return-void

    .line 173
    :catchall_0
    move-exception v1

    :try_start_2
    monitor-exit p0
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_0

    throw v1

    .line 177
    :catch_0
    move-exception v0

    .line 178
    .local v0, ex:Ljava/lang/InterruptedException;
    invoke-static {}, Ljava/lang/Thread;->currentThread()Ljava/lang/Thread;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/Thread;->interrupt()V

    goto :goto_0
.end method

.method public removeQueue(Lcom/nemustech/tiffany/util/TFImageLoader$Cell;)V
    .locals 5
    .parameter "cell"

    .prologue
    .line 44
    monitor-enter p0

    .line 45
    :try_start_0
    iget v2, p1, Lcom/nemustech/tiffany/util/TFImageLoader$Cell;->mKey:I

    invoke-static {v2}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v0

    .line 46
    .local v0, key:Ljava/lang/Integer;
    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mSlotArray:Ljava/util/HashMap;

    invoke-virtual {v2, v0}, Ljava/util/HashMap;->remove(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Lcom/nemustech/tiffany/util/TFImageLoader$Cell;

    .line 47
    .local v1, slot:Lcom/nemustech/tiffany/util/TFImageLoader$Cell;
    if-eqz v1, :cond_0

    .line 49
    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mIndexArray:Ljava/util/LinkedList;

    invoke-virtual {v2, v0}, Ljava/util/LinkedList;->remove(Ljava/lang/Object;)Z

    .line 50
    const-string v2, "TFImageLoader"

    new-instance v3, Ljava/lang/StringBuilder;

    invoke-direct {v3}, Ljava/lang/StringBuilder;-><init>()V

    const-string v4, "Queue index:"

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

    move-result-object v3

    const-string v4, " has been removed from queue."

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v3

    invoke-static {v2, v3}, Landroid/util/Log;->w(Ljava/lang/String;Ljava/lang/String;)I

    .line 52
    :cond_0
    monitor-exit p0

    .line 53
    return-void

    .line 52
    .end local v0           #key:Ljava/lang/Integer;
    .end local v1           #slot:Lcom/nemustech/tiffany/util/TFImageLoader$Cell;
    :catchall_0
    move-exception v2

    monitor-exit p0
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    throw v2
.end method

.method public run()V
    .locals 7

    .prologue
    const/4 v6, 0x1

    .line 113
    iput-boolean v6, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mThreadLive:Z

    .line 116
    :goto_0
    iget-boolean v3, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mThreadLive:Z

    if-eqz v3, :cond_4

    .line 118
    monitor-enter p0

    .line 120
    :try_start_0
    iget-boolean v3, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mPaused:Z

    if-nez v3, :cond_0

    iget-boolean v3, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mIdle:Z
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_1

    if-eqz v3, :cond_1

    .line 123
    :cond_0
    :try_start_1
    const-string v3, "TFImageLoader"

    const-string v4, "Nothing to set or forced to be paused"

    invoke-static {v3, v4}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 124
    invoke-virtual {p0}, Ljava/lang/Object;->wait()V
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_1
    .catch Ljava/lang/InterruptedException; {:try_start_1 .. :try_end_1} :catch_0

    .line 129
    :cond_1
    :try_start_2
    monitor-exit p0
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_1

    .line 131
    iget-object v3, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mIndexArray:Ljava/util/LinkedList;

    invoke-virtual {v3}, Ljava/util/LinkedList;->peek()Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Ljava/lang/Integer;

    .line 133
    .local v2, key:Ljava/lang/Integer;
    if-eqz v2, :cond_3

    .line 135
    iget-object v3, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mSlotArray:Ljava/util/HashMap;

    invoke-virtual {v3, v2}, Ljava/util/HashMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/nemustech/tiffany/util/TFImageLoader$Cell;

    .line 137
    .local v0, cell:Lcom/nemustech/tiffany/util/TFImageLoader$Cell;
    iget-object v3, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mItemUpdateListener:Lcom/nemustech/tiffany/util/TFImageLoader$OnItemUpdateListener;

    iget-object v4, v0, Lcom/nemustech/tiffany/util/TFImageLoader$Cell;->mModel:Lcom/nemustech/tiffany/world/TFModel;

    iget v5, v0, Lcom/nemustech/tiffany/util/TFImageLoader$Cell;->mKey:I

    invoke-interface {v3, v4, v5}, Lcom/nemustech/tiffany/util/TFImageLoader$OnItemUpdateListener;->onItemUpdate(Lcom/nemustech/tiffany/world/TFModel;I)V

    .line 139
    monitor-enter p0

    .line 140
    :try_start_3
    iget-object v3, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mSlotArray:Ljava/util/HashMap;

    invoke-virtual {v3, v2}, Ljava/util/HashMap;->remove(Ljava/lang/Object;)Ljava/lang/Object;

    .line 141
    iget-object v3, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mIndexArray:Ljava/util/LinkedList;

    invoke-virtual {v3, v2}, Ljava/util/LinkedList;->remove(Ljava/lang/Object;)Z

    .line 144
    iget-object v3, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mSlotArray:Ljava/util/HashMap;

    invoke-virtual {v3}, Ljava/util/HashMap;->size()I

    move-result v3

    iget-object v4, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mIndexArray:Ljava/util/LinkedList;

    invoke-virtual {v4}, Ljava/util/LinkedList;->size()I

    move-result v4

    if-eq v3, v4, :cond_2

    .line 145
    const-string v3, "TFImageLoader"

    const-string v4, "Array mismatch !!!!!"

    invoke-static {v3, v4}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    .line 146
    :cond_2
    monitor-exit p0

    goto :goto_0

    :catchall_0
    move-exception v3

    monitor-exit p0
    :try_end_3
    .catchall {:try_start_3 .. :try_end_3} :catchall_0

    throw v3

    .line 125
    .end local v0           #cell:Lcom/nemustech/tiffany/util/TFImageLoader$Cell;
    .end local v2           #key:Ljava/lang/Integer;
    :catch_0
    move-exception v3

    move-object v1, v3

    .line 126
    .local v1, e:Ljava/lang/InterruptedException;
    :try_start_4
    monitor-exit p0

    .line 154
    .end local v1           #e:Ljava/lang/InterruptedException;
    :goto_1
    return-void

    .line 129
    :catchall_1
    move-exception v3

    monitor-exit p0
    :try_end_4
    .catchall {:try_start_4 .. :try_end_4} :catchall_1

    throw v3

    .line 150
    .restart local v2       #key:Ljava/lang/Integer;
    :cond_3
    iput-boolean v6, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mIdle:Z

    goto :goto_0

    .line 153
    .end local v2           #key:Ljava/lang/Integer;
    :cond_4
    const-string v3, "TFImageLoader"

    const-string v4, "Thread Paused."

    invoke-static {v3, v4}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    goto :goto_1
.end method

.method public setItemUpdateListener(Lcom/nemustech/tiffany/util/TFImageLoader$OnItemUpdateListener;)V
    .locals 0
    .parameter "updateItemListener"

    .prologue
    .line 187
    iput-object p1, p0, Lcom/nemustech/tiffany/util/TFImageLoader;->mItemUpdateListener:Lcom/nemustech/tiffany/util/TFImageLoader$OnItemUpdateListener;

    .line 188
    return-void
.end method
